# encoding: utf-8
import random

class Warrior(object):
    """
    战士
    """
    def __init__(self,name,strength,dexterity,stamina,intelligence,exp):
        self.name = name
        self.add_exp = 0
        self._exp = exp
        self._strength = strength
        self._dexterity = dexterity
        self._stamina = stamina
        self._intelligence = intelligence
        self.head = Blank()
        self.body = Blank()
        self.hand = Blank()
        self.foot = Blank()
        self.weapon = Blank()
        self._hp = self.max_hp
        self._mp = self.max_mp
        self.money = 0
        
    def equip(self,obj):
        if isinstance(obj,EquipHead):
            return self.equip_head(obj)
        elif isinstance(obj,EquipBody):
            return self.equip_body(obj)
        elif isinstance(obj,EquipHand):
            return self.equip_hand(obj)
        elif isinstance(obj,EquipFoot):
            return self.equip_foot(obj)
        elif isinstance(obj,EquipWeapon):
            return self.equip_weapon(obj)
        
    def unequip(self,obj):
        if isinstance(obj,EquipHead):
            return self.unequip_head(obj)
        elif isinstance(obj,EquipBody):
            return self.unequip_body(obj)
        elif isinstance(obj,EquipHand):
            return self.unequip_hand(obj)
        elif isinstance(obj,EquipFoot):
            return self.unequip_foot(obj)
        elif isinstance(obj,EquipWeapon):
            return self.unequip_weapon(obj)
    
    def take_medicine(self,medicine):
        self.hp += medicine.hp
        return 1
            
    def equip_head(self,head):
        self.head = head
        return 1
    
    def equip_body(self,body):
        self.body = body
        return 1
    
    def equip_hand(self,hand):
        self.hand = hand
        return 1
    
    def equip_foot(self,foot):
        self.foot = foot
        return 1
    
    def equip_weapon(self,weapon):
        self.weapon = weapon
        return 1
    
    def unequip_head(self,head):
        self.head = Blank()
        return 1
    
    def unequip_body(self,body):
        self.body = Blank()
        return 1
    
    def unequip_hand(self,hand):
        self.hand = Blank()
        return 1
    
    def unequip_foot(self,foot):
        self.foot = Blank()
        return 1
    
    def unequip_weapon(self,weapon):
        self.weapon = Blank()
        return 1
    
    def bag(self,Bag):
        self.bag = Bag
        return 1

    @property
    def hp(self):
        return self._hp

    @hp.setter
    def hp(self,hp):
        self._hp = hp
        if self._hp > self.max_hp:
            self._hp = self.max_hp
        else:
            self._hp = hp
            
    @property
    def mp(self):
        return self._mp
    
    @mp.setter
    def mp(self,mp):
        self._mp = mp
        if self._mp > self.max_mp:
            self._mp = self.max_mp
        else:
            self._mp = mp

    @property
    def level(self):
        return self.exp/100 + 1    
    
    @property
    def exp(self):
        return self._exp + self.add_exp    
         
    @property
    def defence(self):
        return self.dexterity * 2 + 50
    
    @property
    def intelligence(self):
        return self._intelligence + self.head.intelligence + self.body.intelligence + self.hand.intelligence + self.foot.intelligence + self.weapon.intelligence
        
    @property
    def max_mp(self):
        return self.intelligence * 0
        
    @property
    def max_hp(self):
        return self.stamina * 10
    
    @property
    def stamina(self):
        return self._stamina + self.level*10 + self.head.stamina + self.body.stamina + self.hand.stamina + self.foot.stamina + self.weapon.stamina
        
    @property
    def ap(self):
        return self.strength*2 + self.dexterity
                 
    @property
    def strength(self):
        return self._strength + self.level*8 + self.head.strength + self.body.strength + self.hand.strength + self.foot.strength + self.weapon.strength
    
    @property
    def dexterity(self):
        return self._dexterity + self.level*5 + self.head.dexterity + self.body.dexterity + self.hand.dexterity + self.foot.dexterity + self.weapon.dexterity 
        
    def over(self,enemy):
        if enemy.hp <= 0:
            return True
        return False
    
    def pk(self,enemy):
        enemy.hp = enemy.hp - (self.ap*1.5 - enemy.defence + random.randint(0,3))
        if self.over(enemy):
            enemy.hp = 0
            self.money += enemy.money
            self.add_exp += enemy.exp
        return enemy.hp
        
    def __str__(self):
        return self.name
        
class Enemy(object):
    """
    敌人
    """
    def __init__(self,name,hp,attack,defence,level):
        self.name = name
        self.hp = hp
        self.money = level * 100
        self.exp = level * 50
        self.attack = attack
        self.defence = defence
    
    def over(self,hero):
        if hero.hp <= 0:
            return True
        return False
    
    def pk(self,hero):
        hero.hp = hero.hp - (self.attack - hero.defence + random.randint(0,3))
        if self.over(hero):
            hero.hp = 0
        return hero.hp    

    def __str__(self):
        return self.name
    
class Bag(object):
    """
    背包
    """
    def __init__(self,size):
        self.bag = []
        self.size = size
    
    def __len__(self):
        return self.size
    
    def __add__(self,items):
        return self.bag.append(items)
    
class Medicine(object):
    """
    药品
    """
    def __init__(self,name,hp,mp):
        self.name = name
        self.hp = hp
        self.mp = mp
        
    def __str__(self):
        return self.name
    
def __init__(self,name,strength,dexterity,stamina,intelligence,level=0):
    self.name = name
    self.strength = strength
    self.dexterity = dexterity
    self.stamina = stamina
    self.intelligence = intelligence
    self.level = level
    self.money = level*10 + strength*2 + dexterity*2 + stamina*5 + intelligence*2
    
def __str__(self):
    return self.name

EquipHead = type('EquipHead',(object,),{'__init__':__init__,'__str__':__str__})
EquipBody = type('EquipBody',(object,),{'__init__':__init__,'__str__':__str__})
EquipHand = type('EquipHand',(object,),{'__init__':__init__,'__str__':__str__})
EquipFoot = type('EquipFoot',(object,),{'__init__':__init__,'__str__':__str__})
EquipWeapon = type('EquipWeapon',(object,),{'__init__':__init__,'__str__':__str__})

class Blank(object):
    def __getattribute__(self,name):
        return 0    